package com.danicsoft.daide.serverclient;

import java.util.List;

import com.danicsoft.daide.command.OrderSpec;


/**
 * All the methods used for interacting with a server. A client uses these to
 * get information from the server.
 * 
 * @author Daniel Yule (daniel.yule@gmail.com)
 * @version 1.0
 */
public interface Server {

	/**
	 * Gets the information (supply centre location, army position and order
	 * resolution) for the current turn.
	 * 
	 * @return The information for the current turn
	 * @throws IllegalServerStateException
	 *         If the game had not started yet or was paused.
	 */
	public TurnInfo getCurrentTurnInfo() throws IllegalServerStateException;

	/**
	 * Gets the map definition for this game.
	 * 
	 * @return An object representing the Map for the game.
	 * @throws IllegalServerStateException
	 *         If the game has ended.
	 */
	public MapInfo getMapInfo() throws IllegalServerStateException;

	/**
	 * Gets the variant information for this server.
	 * 
	 * @return The variant information for this game.
	 * @throws IllegalServerStateException
	 *         If the game has not started yet or has ended.
	 */
	public VariantInfo getVariantInfo() throws IllegalServerStateException;

	/**
	 * Submit orders to the server. If orders are missing, the player will be
	 * notified as such.
	 * 
	 * @param orders
	 *        The orders to submit.
	 * @param power
	 *        The power these are the orders for.
	 * @throws IllegalServerStateException
	 *         If the game has not started, or has ended.
	 */
	public void submitOrders(List<OrderSpec> orders, Player power) throws IllegalServerStateException;

	/**
	 * Cancel orders previously sent.
	 * 
	 * @param power
	 *        The power to cancel them for.
	 * @throws IllegalServerStateException
	 *         If the game has not started, or has ended.
	 */
	public void unsubmitOrders(Player power) throws IllegalServerStateException;

	/**
	 * Unsubmit the orders specified.
	 * 
	 * @param orders
	 *        The orders to cancel.
	 * @param power
	 *        The power responsible for cancelling this order.
	 * @return True if the server was able to cancel the order, false otherwise.
	 */
	public boolean unsubmitOrder(List<OrderSpec> orders, Player power);

	/**
	 * Join the game as a player.
	 * 
	 * @param player
	 *        The player that is joining
	 * @return True if we were able to join, false otherwise.
	 */
	public boolean join(Player player);

	/**
	 * Inform the server that we are ready to play.
	 * 
	 * @param player
	 *        The player that is ready
	 * @return True if we are allowed to play this game, false otherwise.
	 */
	public boolean ready(Player player);

	/**
	 * Join the game as an observer.
	 * 
	 * @param player
	 *        The player to observe as.
	 * @return True if we are able to be an observer, false otherwise.
	 */
	public boolean observe(Player player);

	/**
	 * @param player
	 *        The player that is rejoining
	 * @return true if we were able to rejoin the game as the given power, false
	 *         otherwise.
	 */
	public boolean rejoin(Player player);

	/**
	 * Informs the server that a player has left momentarily, but may be back.
	 * 
	 * @param leftPlayer
	 *        The player that has left.
	 */
	public void left(Player leftPlayer);

}
